#include <cstdio>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <string>
const std::string pathname = ".";
const int proj_id = 066;
const size_t gsize = 4096;
int main()
{
    key_t key = ftok(pathname.c_str(), proj_id);
    int id = shmget(key, gsize, IPC_CREAT | IPC_EXCL | 0666);
    if (id < 0)
    {
        perror("create shm failed");
        exit(1);
    }
    else
    {
        printf("create shm create!\n");
    }
    // 销毁
    int n = shmctl(id, IPC_RMID, nullptr);
    if (n < 0)
    {
        perror("destroy shm failed");
        exit(2);
    }
    else
    {
        printf("destroy shm success\n");
    }

    return 0;
}
